// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.QueryDsl;

public sealed partial class TokenPruningConfig
{
	/// <summary>
	/// <para>
	/// Whether to only score pruned tokens, vs only scoring kept tokens.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("only_score_pruned_tokens")]
	public bool? OnlyScorePrunedTokens { get; set; }

	/// <summary>
	/// <para>
	/// Tokens whose frequency is more than this threshold times the average frequency of all tokens in the specified field are considered outliers and pruned.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("tokens_freq_ratio_threshold")]
	public int? TokensFreqRatioThreshold { get; set; }

	/// <summary>
	/// <para>
	/// Tokens whose weight is less than this threshold are considered nonsignificant and pruned.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("tokens_weight_threshold")]
	public float? TokensWeightThreshold { get; set; }
}

public sealed partial class TokenPruningConfigDescriptor : SerializableDescriptor<TokenPruningConfigDescriptor>
{
	internal TokenPruningConfigDescriptor(Action<TokenPruningConfigDescriptor> configure) => configure.Invoke(this);

	public TokenPruningConfigDescriptor() : base()
	{
	}

	private bool? OnlyScorePrunedTokensValue { get; set; }
	private int? TokensFreqRatioThresholdValue { get; set; }
	private float? TokensWeightThresholdValue { get; set; }

	/// <summary>
	/// <para>
	/// Whether to only score pruned tokens, vs only scoring kept tokens.
	/// </para>
	/// </summary>
	public TokenPruningConfigDescriptor OnlyScorePrunedTokens(bool? onlyScorePrunedTokens = true)
	{
		OnlyScorePrunedTokensValue = onlyScorePrunedTokens;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Tokens whose frequency is more than this threshold times the average frequency of all tokens in the specified field are considered outliers and pruned.
	/// </para>
	/// </summary>
	public TokenPruningConfigDescriptor TokensFreqRatioThreshold(int? tokensFreqRatioThreshold)
	{
		TokensFreqRatioThresholdValue = tokensFreqRatioThreshold;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Tokens whose weight is less than this threshold are considered nonsignificant and pruned.
	/// </para>
	/// </summary>
	public TokenPruningConfigDescriptor TokensWeightThreshold(float? tokensWeightThreshold)
	{
		TokensWeightThresholdValue = tokensWeightThreshold;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (OnlyScorePrunedTokensValue.HasValue)
		{
			writer.WritePropertyName("only_score_pruned_tokens");
			writer.WriteBooleanValue(OnlyScorePrunedTokensValue.Value);
		}

		if (TokensFreqRatioThresholdValue.HasValue)
		{
			writer.WritePropertyName("tokens_freq_ratio_threshold");
			writer.WriteNumberValue(TokensFreqRatioThresholdValue.Value);
		}

		if (TokensWeightThresholdValue.HasValue)
		{
			writer.WritePropertyName("tokens_weight_threshold");
			writer.WriteNumberValue(TokensWeightThresholdValue.Value);
		}

		writer.WriteEndObject();
	}
}